﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.ReceptionGoods
{
    public partial class NewNkld : Form
    {
        Int32 _contragentId;
        public NewNkld(Int32 contragentId)
        {
            InitializeComponent();
            _contragentId = contragentId;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddNkld();
        }
        private void AddNkld()
        
        {
            DataSets.waybillsDataTableAdapters.SupplierInvoiceDocInsertTableAdapter adapter = new DIProject.DataSets.waybillsDataTableAdapters.SupplierInvoiceDocInsertTableAdapter();
            DataSets.waybillsData.SupplierInvoiceDocInsertDataTable dt;
            DateTime DocDate = DateTime.Now;
            string DocNumber = null;
            DateTime ContragentDocDate = dtpDDP.Value;
            string ContragentDocNumber = txbNumDoc.Text;
            
            DateTime? PaymentDate = null; 
            if (dtpDO.Checked)
            {
                PaymentDate = dtpDO.Value;
                if (DocDate > PaymentDate.Value)
                {
                    MessageBox.Show("Дата оплаты д.б. больше даты приходной накладной!");
                    return;
                }
            }
            string Note = txbNote.Text;
            DateTime MD = DateTime.Now;
            string MW = FirstForm.Login;
            dt = adapter.GetData(DocDate, DocNumber, _contragentId, ContragentDocDate, ContragentDocNumber, PaymentDate, Note, MD, MW);
            this.Close();
        }
    }
}